<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<title>Exported from Notepad++</title>
<style type="text/css">
span {
	font-family: 'Courier New';
	font-size: 10pt;
	color: #000000;
}
.sc0 {
}
.sc2 {
	font-style: italic;
	color: #0000FF;
}
.sc4 {
	color: #8000FF;
}
.sc5 {
	font-weight: bold;
	font-style: italic;
	color: #0000FF;
}
.sc6 {
	font-weight: bold;
	color: #008000;
}
.sc7 {
	font-style: italic;
	text-decoration: underline;
	color: #FF0000;
}
.sc8 {
	font-weight: bold;
	font-style: italic;
	color: #008000;
}
.sc10 {
	font-weight: bold;
	color: #0080FF;
}
.sc11 {
}
.sc14 {
	color: #8080FF;
}
</style>
</head>
<body>
<div style="float: left; white-space: pre; line-height: 1; background: #FFFFFF; "><span class="sc2">// ================================================== //</span><span class="sc0">
</span><span class="sc2">// ============ TUTORIELS BEBOP 1.0 ================= //</span><span class="sc0">
</span><span class="sc2">// ================================================== //</span><span class="sc0">

</span><span class="sc2">// Net list d'une montre digitale pipee avec un cadran</span><span class="sc0">
</span><span class="sc2">// graphique avec des afficheurs 7-segments</span><span class="sc0">

</span><span class="sc2">// Equivalent au la commande shell en pipe :</span><span class="sc0">
</span><span class="sc2">// $./freq.bpix -f 2 -ni | bopsimu montre.bop -p | ./cadran</span><span class="sc0">

</span><span class="sc10">#</span><span class="sc5">include</span><span class="sc0"> </span><span class="sc14">"montre.bop"</span><span class="sc0">

</span><span class="sc10">#</span><span class="sc5">define</span><span class="sc0"> </span><span class="sc8">LINUX</span><span class="sc0"> </span><span class="sc4">0</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">define</span><span class="sc0"> </span><span class="sc8">WINDOWS</span><span class="sc0"> </span><span class="sc4">1</span><span class="sc0">

</span><span class="sc2">// Selon l'OS, on n'a pas le meme PATH pour le repertoire courant</span><span class="sc0">
</span><span class="sc2">// La variable CURRENT_OS est disponible pour connaitre l'OS courant.</span><span class="sc0">
</span><span class="sc2">// On specifie le lien vers l'application cadran et montre sous linux</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">define</span><span class="sc0"> </span><span class="sc8">PATH</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc0"> </span><span class="sc8">CURRENT_OS</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc8">LINUX</span><span class="sc0"> </span><span class="sc11">?</span><span class="sc0"> </span><span class="sc14">"./"</span><span class="sc0"> </span><span class="sc10">:</span><span class="sc0"> </span><span class="sc14">""</span><span class="sc0"> </span><span class="sc10">)</span><span class="sc0">

</span><span class="sc2">// On reprend la meme frequence que dans montre.bop</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">define</span><span class="sc0"> </span><span class="sc8">FREQ</span><span class="sc0"> </span><span class="sc4">2</span><span class="sc0">

</span><span class="sc2">// Montre doit etre interpretee ou native ?</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">define</span><span class="sc0"> </span><span class="sc8">NATIVE</span><span class="sc0"> </span><span class="sc4">0</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">define</span><span class="sc0"> </span><span class="sc8">INTERPRETEE</span><span class="sc0"> </span><span class="sc4">1</span><span class="sc0">

</span><span class="sc10">#</span><span class="sc5">define</span><span class="sc0"> </span><span class="sc8">MONTRE_EXE</span><span class="sc0"> </span><span class="sc8">INTERPRETEE</span><span class="sc0"> </span><span class="sc2">// Choisir entre native et interpretee</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">define</span><span class="sc0"> </span><span class="sc8">RunTime</span><span class="sc0"> </span><span class="sc14">""</span><span class="sc0"> </span><span class="sc2">// choisir entre "" et "-m"</span><span class="sc0">

</span><span class="sc2">// Une fonction de simulation qui encapsule les appels systemes.</span><span class="sc0">
</span><span class="sc2">// la syntaxe $(...) permet d'acceder aux variables #define</span><span class="sc0">

</span><span class="sc2">// L'option -m de freq permet de faire comme si on avait lancee l'application a minuit</span><span class="sc0">
</span><span class="sc2">// Pendant un temps, la simulation s'emballe, puis se stabilise a l'heure courante.</span><span class="sc0">

</span><span class="sc8">MontreNative</span><span class="sc0"> </span><span class="sc10">()</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc11">s</span><span class="sc10">:[</span><span class="sc4">42</span><span class="sc10">]</span><span class="sc0">
</span><span class="sc5">where</span><span class="sc0">
    </span><span class="sc11">s</span><span class="sc10">:[</span><span class="sc4">42</span><span class="sc10">]</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc6">pipe</span><span class="sc10">(</span><span class="sc14">"$(PATH)montre"</span><span class="sc10">);</span><span class="sc0">
</span><span class="sc5">end</span><span class="sc0"> </span><span class="sc5">where</span><span class="sc10">;</span><span class="sc0">

</span><span class="sc8">MontreInterpretee</span><span class="sc0"> </span><span class="sc10">()</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc11">s</span><span class="sc10">:[</span><span class="sc4">42</span><span class="sc10">]</span><span class="sc0">
</span><span class="sc5">where</span><span class="sc0">
    </span><span class="sc11">s</span><span class="sc10">:[</span><span class="sc4">42</span><span class="sc10">]</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc8">Montre</span><span class="sc10">.</span><span class="sc8">Montre</span><span class="sc10">();</span><span class="sc0">
</span><span class="sc2">//  s:[42] = pipe("bopsimu montre.bop -p"); // également possible</span><span class="sc0">
</span><span class="sc5">end</span><span class="sc0"> </span><span class="sc5">where</span><span class="sc10">;</span><span class="sc0">

</span><span class="sc10">[</span><span class="sc7">Main</span><span class="sc10">]</span><span class="sc0">
</span><span class="sc8">Simulation</span><span class="sc0"> </span><span class="sc10">()</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc10">()</span><span class="sc0">
</span><span class="sc5">where</span><span class="sc0">
    </span><span class="sc5">if</span><span class="sc0"> </span><span class="sc8">MONTRE_EXE</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc8">NATIVE</span><span class="sc0">
    </span><span class="sc5">then</span><span class="sc0">
        </span><span class="sc11">s</span><span class="sc10">:[</span><span class="sc4">42</span><span class="sc10">]</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc8">MontreNative</span><span class="sc10">();</span><span class="sc0">
    </span><span class="sc5">else</span><span class="sc0">
        </span><span class="sc11">s</span><span class="sc10">:[</span><span class="sc4">42</span><span class="sc10">]</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc8">MontreInterpretee</span><span class="sc10">();</span><span class="sc0">
    </span><span class="sc5">end</span><span class="sc0"> </span><span class="sc5">if</span><span class="sc10">;</span><span class="sc0">
    
    </span><span class="sc2">// Regulateur de frequence</span><span class="sc0">
    </span><span class="sc11">_</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc6">pipe</span><span class="sc10">(</span><span class="sc14">"$(PATH)freq.bpix $(RunTime) -f $(FREQ)"</span><span class="sc10">);</span><span class="sc0">

    </span><span class="sc2">// Envoyer les bits de sortie dans le cadran</span><span class="sc0">
    </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc6">pipe</span><span class="sc10">(</span><span class="sc14">"$(PATH)cadran"</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc11">s</span><span class="sc10">:[</span><span class="sc4">42</span><span class="sc10">]);</span><span class="sc0">
</span><span class="sc5">end</span><span class="sc0"> </span><span class="sc5">where</span><span class="sc10">;</span><span class="sc0">
</span></div></body>
</html>
